package com.jtny.nytb.equipment.service;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.jtny.component.entity.PageData;
import com.jtny.component.entity.PageParam;
import com.jtny.component.exception.ServiceException;
import com.jtny.nytb.equipment.dto.dataparam.LabelTempDTO;
import com.jtny.nytb.equipment.dto.device.*;
import com.jtny.nytb.equipment.dto.equipment.EquipmentModelPageQueryParamDTO;

import com.jtny.nytb.equipment.dto.model.ExcelModelParamDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author 智慧能源中心 - zx
 * @package com.jtny.nytb.energymonitor.equipment.service
 * @fileName EquipmentInfoService.java
 * @createTime 2023年09月19日 22:50
 * @Copyright© 2023 jtny
 * 江投能源技术研究院 版权所有
 */
@Api(value = "设备管理Service接口", tags = "设备管理Service接口")
@ApiSort(202302)
@ResponseBody
public interface EquipmentInfoService {

    /**
     * 查询分页设备信息
     *
     * @param equipmentInfoQueryPageParamDTO
     * @return
     * @throws ServiceException
     */
    @ApiOperation("查询分页设备信息")
    @ApiImplicitParam(name = "equipmentInfoQueryPageParamDTO", value = "设备信息查询对象DTO", required = true, paramType = "query", dataType = "EquipmentInfoQueryPageParamDTO")
    @ApiOperationSupport(order = 1)
    @PostMapping("/queryPage")
    PageData<EquipmentInfoDTO> queryPage(@RequestBody EquipmentInfoQueryPageParamDTO equipmentInfoQueryPageParamDTO) throws ServiceException;

    @ApiOperation("查询分页设备信息")
    @ApiImplicitParam(name = "equipmentInfoQueryPageParamDTO", value = "设备信息查询对象DTO", required = true, paramType = "query", dataType = "EquipmentInfoQueryPageParamDTO")
    @ApiOperationSupport(order = 1)
    @PostMapping("/listByParam")
    List<EquipmentInfoDTO> listByParam(@RequestBody EquipmentInfoQueryPageParamDTO equipmentInfoQueryPageParamDTO) throws ServiceException;


    /**
     * 修改设备信息
     *
     * @param equipmentInfoDTO
     * @return
     * @throws ServiceException
     */
    @ApiOperation("修改设备信息")
    @ApiImplicitParam(name = "equipmentInfoDTO", value = "修改设备信息对象DTO", required = true, paramType = "query", dataType = "EquipmentInfoDTO")
    @ApiOperationSupport(order = 2)
    @PostMapping("/update")
    EquipmentInfoDTO update(@RequestBody EquipmentInfoDTO equipmentInfoDTO) throws ServiceException;


    /**
     * 通过设备id查询单个设备信息
     *
     * @param id 设备id
     * @return
     * @throws ServiceException
     */
    @ApiOperation("通过设备id查询设备信息")
    @ApiImplicitParam(name = "主键id", value = "主键id", required = true, paramType = "path")
    @ApiOperationSupport(order = 3)
    @GetMapping("/getById/{id}")
    EquipmentInfoDTO getById(@PathVariable("id") Long id) throws ServiceException;


    /**
     * 更新设备状态
     *
     * @param id     编号
     * @param status 地位
     * @throws ServiceException 服务异常
     */
    @ApiOperation("修改设备状态")
    @ApiImplicitParam(name = "id", value = "设备id", required = true, paramType = "path")
    @ApiOperationSupport(order = 4)
    @PostMapping("/updateStatus/{id}/{status}")
    void updateEquipmentStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status) throws ServiceException;

    /**
     * 通过名字获取设备
     *
     * @param name 名字
     * @return {@link EquipmentInfoDTO}
     * @throws ServiceException 服务异常
     */
    @ApiOperation("通过设备名字查询设备信息")
    @ApiImplicitParam(name = "名字", value = "名字", required = true, paramType = "path")
    @ApiOperationSupport(order = 3)
    @PostMapping("/getByName")
    EquipmentInfoDTO getEquipmentByName(@RequestBody String name) throws ServiceException;

    /**
     * 通过名字列表获 批量取设备
     *
     * @param nameList 名字列表
     * @return {@link Map}<{@link String}, {@link EquipmentInfoDTO}> key: 设备名字 value: 设备信息
     * @throws ServiceException
     */
    @ApiOperation("通过设备名字列表批量查询设备信息")
    @ApiImplicitParam(name = "名字列表", value = "名字列表", required = true, paramType = "query", dataType = "List<String>")
    @ApiOperationSupport(order = 3)
    @PostMapping("/map-equipment-name-list/{type}")
    Map<String, EquipmentInfoDTO> mapEquipmentByNameList(@PathVariable("type") String type, @RequestBody Set<String> nameList) throws ServiceException;

    /**
     * 通过设备上报标识List获取设备
     *
     * @param dockIdentifierList 设备上报标识List
     * @return {@link Map}<{@link String}, {@link EquipmentInfoDTO}> key: 设备名字 value: 设备信息
     * @throws ServiceException
     */
    @ApiOperation("通过设备名字列表批量查询设备信息")
    @ApiImplicitParam(name = "名字列表", value = "名字列表", required = true, paramType = "query", dataType = "List<String>")
    @ApiOperationSupport(order = 3)
    @PostMapping("/map-equipment-dock-identifier-list/{type}")
    Map<String, EquipmentInfoDTO> mapEquipmentByDockIdentifierList(@PathVariable("type") String type, @RequestBody Set<String> dockIdentifierList) throws ServiceException;


    /**
     * 通过设备code查询单个设备信息
     *
     * @param code 设备code
     * @return
     * @throws ServiceException
     */
    @ApiOperation("通过设备code查询设备信息")
    @ApiImplicitParam(name = "主键id", value = "主键id", required = true, paramType = "path")
    @ApiOperationSupport(order = 3)
    @GetMapping("/getByCode/{code}")
    EquipmentInfoDTO getByCode(@PathVariable("code") String code) throws ServiceException;


    /**
     * 查询分页设备参数信息
     *
     * @param equipmentInfoParamPageQueryDTO
     * @return
     * @throws ServiceException
     */
    @ApiOperation("查询分页设备参数信息")
    @ApiImplicitParam(name = "equipmentInfoParamPageQueryDTO", value = "设备参数信息查询对象DTO", required = true, paramType = "query", dataType = "EquipmentInfoParamPageQueryDTO")
    @ApiOperationSupport(order = 4)
    @PostMapping("/queryPageParam")
    PageData<EquipmentInfoParamDTO> queryPageParam(@RequestBody EquipmentInfoParamPageQueryDTO equipmentInfoParamPageQueryDTO) throws ServiceException;

    /**
     * 保存设备参数信息
     *
     * @param equipmentInfoParamDTOTwo
     * @return
     * @throws ServiceException
     */
    @ApiOperation("保存设备参数信息")
    @ApiImplicitParam(name = "equipmentInfoParamDTO", value = "保存设备参数信息对象DTO", required = true, paramType = "query", dataType = "EquipmentInfoParamDTO")
    @ApiOperationSupport(order = 5)
    @PostMapping("/savaParam")
    EquipmentInfoParamDTO savaParam(@RequestBody EquipmentInfoParamDTO equipmentInfoParamDTOTwo) throws ServiceException;


    /**
     * 保存设备参数信息List
     *
     * @param equipmentInfoParamList 设备参数信息List
     * @throws ServiceException 服务异常
     */
    @PostMapping("/savaParamList")
    void saveParamList(@RequestBody List<EquipmentInfoParamDTO> equipmentInfoParamList) throws ServiceException;

    /**
     * 保存设备信息
     *
     * @param equipmentInfoDTO
     * @return
     * @throws ServiceException
     */
    @ApiOperation("保存设备信息")
    @ApiImplicitParam(name = "equipmentInfoDTO", value = "保存设备信息对象DTO", required = true, paramType = "query", dataType = "EquipmentInfoDTO")
    @ApiOperationSupport(order = 9)
    @PostMapping("/save")
    EquipmentInfoDTO save(@RequestBody EquipmentInfoDTO equipmentInfoDTO) throws ServiceException;


    /**
     * 通过设备参数id查询多个设备参数信息
     *
     * @param id
     * @return
     * @throws ServiceException
     */
    @ApiOperation("通过设备参数id查询单个设备参数信息")
    @ApiImplicitParam(name = "主键id", value = "主键id", required = true, paramType = "path")
    @ApiOperationSupport(order = 10)
    @GetMapping("/getByIdParams/{id}")
    List<EquipmentInfoParamDTO> getByIdParams(@PathVariable("id") Long id) throws ServiceException;


    /**
     * 通过设备参数id查询单个设备参数信息
     *
     * @param id
     * @return
     * @throws ServiceException
     */
    @ApiOperation("通过设备参数id查询单个设备参数信息")
    @ApiImplicitParam(name = "主键id", value = "主键id", required = true, paramType = "path")
    @ApiOperationSupport(order = 6)
    @GetMapping("/getByIdParam/{id}")
    EquipmentInfoParamDTO getByIdParam(@PathVariable("id") Long id) throws ServiceException;

    /**
     * 修改设备参数信息
     *
     * @param equipmentInfoParamDTOTwo
     * @return
     * @throws ServiceException
     */
    @ApiOperation("修改设备参数信息")
    @ApiImplicitParam(name = "equipmentInfoParamDTO", value = "修改设备模型信息对象DTO", required = true, paramType = "query", dataType = "EquipmentInfoParamDTO")
    @ApiOperationSupport(order = 7)
    @PostMapping("/updateParam")
    EquipmentInfoParamDTO updateParam(@RequestBody EquipmentInfoParamDTO equipmentInfoParamDTOTwo) throws ServiceException;

    /**
     * 通过设备code查询设备信息
     *
     * @param code
     * @return
     * @throws ServiceException
     */
    @ApiOperation("通过设备code查询设备信息")
    @ApiImplicitParam(name = "code", value = "设备code", required = true, paramType = "path")
    @ApiOperationSupport(order = 8)
    @GetMapping("/detailsEquCode/{code}")
    EquipmentInfoDTO detailsEquCode(@PathVariable("code") String code) throws ServiceException;

    @ApiOperation("通过设备列表code查询设备信息")
    @ApiImplicitParam(name = "code", value = "设备code", required = true, paramType = "path")
    @ApiOperationSupport(order = 8)
    @PostMapping("/detailsEquCodeList")
    List<EquipmentInfoDTO> detailsEquCodeList(@RequestBody List<String> codes) throws ServiceException;

    /**
     * 条件查询
     *
     * @param equipmentModelPageQueryParamDTO 条件查询
     * @return
     * @throws ServiceException
     */
    @GetMapping("/listByQueryParam")
    List<EquipmentInfoDTO> listByQueryParam(@SpringQueryMap EquipmentModelPageQueryParamDTO equipmentModelPageQueryParamDTO) throws ServiceException;

    /**
     * 通过查询参数列出设备 ID
     *
     * @param equipmentModelPageQueryParamDTO 设备型号页面查询参数 DTO
     * @return {@link List}<{@link Long}>
     * @throws ServiceException 服务异常
     */
    @PostMapping("/list-equipment-id-query")
    List<Long> listEquipmentIdByQueryParam(@RequestBody EquipmentModelPageQueryParamDTO equipmentModelPageQueryParamDTO) throws ServiceException;

    /**
     * @param equipmentIdList 设备 ID 列表
     * @return {@link Map}<{@link Long}, {@link EquipmentInfoDTO}> key: 设备 ID value: 设备信息
     */
    @PostMapping("/map-equipment-id")
    Map<Long, EquipmentInfoDTO> mapEquipmentInfoByIds(@RequestBody Collection<Long> equipmentIdList);


    @PostMapping("/pageDeviceByParams")
    PageData<EquipmentInfoDTO> pageDeviceByParams(@RequestBody EquipmentModelPageQueryParamDTO pageQueryParamDTO);

    /**
     * 查询所有设备信息
     *
     * @return
     * @throws ServiceException
     */
    @ApiOperation("查询所有设备信息")
    @GetMapping("/getAllDevice")
    List<EquipmentInfoDTO> getAllDevice() throws ServiceException;

    /**
     * 导入设备
     *
     * @param type          类型
     * @param equipmentList 设备清单
     * @return {@link Map}<{@link Long}, {@link String}> key: equipmentId value: equipmentCode
     */
    @ApiOperation("导入设备信息")
    @PostMapping("import-equipment/{type}")
    Map<Long, String> importEquipment(@PathVariable("type") String type,
                                      @RequestBody List<EquipmentExcelDTO> equipmentList);

    /**
     * 导入设备参数
     *
     * @param type                       类型
     * @param equipmentModelParamDTOList 设备模型参数列表
     */
    @ApiOperation("导入设备参数信息")
    @PostMapping("import-equipment-param/{type}")
    void importEquipmentModelParam(@PathVariable("type") String type,
                                   @RequestBody List<ExcelModelParamDTO> equipmentModelParamDTOList);


    /**
     * 设备标签分页
     *
     * @param equipmentId 设备 ID
     * @param param       参数
     * @return {@link PageData}<{@link LabelTempDTO}>
     */
    @ApiOperation("设备标签分页")
    @ApiImplicitParam(name = "equipmentId", value = "设备ID", required = true,
            paramType = "query", dataType = "long")
    @ApiOperationSupport(order = 10)
    @GetMapping("label/queryPage/{equipmentId}")
    PageData<LabelTempDTO> queryPageLabel(@PathVariable("equipmentId") Long equipmentId, @SpringQueryMap PageParam param);

    /**
     * 设备标签添加
     *
     * @param equipmentId  设备 ID
     * @param labelTempDTO 标签临时 DTO
     */
    @ApiOperation("设备标签添加")
    @ApiImplicitParam(name = "equipmentId", value = "设备ID", required = true,
            paramType = "query", dataType = "long")
    @ApiOperationSupport(order = 10)
    @PostMapping("label/save/{equipmentId}")
    void saveLabel(@PathVariable("equipmentId") Long equipmentId, @RequestBody LabelTempDTO labelTempDTO);


    /**
     * 设备标签添加
     *
     * @param equipmentId      设备 ID
     * @param labelTempDTOList 标签临时 DTO
     */
    @ApiOperation("设备标签添加")
    @ApiImplicitParam(name = "equipmentId", value = "设备ID", required = true,
            paramType = "query", dataType = "long")
    @ApiOperationSupport(order = 10)
    @PostMapping("label/save-list/{equipmentId}")
    void saveEquipmentLabelList(@PathVariable("equipmentId") Long equipmentId, @RequestBody List<LabelTempDTO> labelTempDTOList);

    /**
     * 设备标签删除
     *
     * @param equipmentId 编号
     * @param labelItemId 标签项 ID
     */
    @ApiOperation("设备标签删除")
    @ApiImplicitParam(name = "id", value = "设备ID", required = true,
            paramType = "query", dataType = "long")
    @ApiOperationSupport(order = 10)
    @DeleteMapping("label/delete/{equipmentId}/{labelItemId}")
    void deleteLabel(@PathVariable("equipmentId") Long equipmentId, @PathVariable("labelItemId") Long labelItemId);

    /**
     * 按设备 ID 列出设备标签
     *
     * @param equipmentId 设备 ID
     * @return {@link List}<{@link LabelTempDTO}>
     */
    @ApiOperation("设备标签查询")
    @ApiImplicitParam(name = "equipmentId", value = "设备ID", required = true,
            paramType = "query", dataType = "long")
    @ApiOperationSupport(order = 11)
    @GetMapping("label/list/{equipmentId}")
    List<LabelTempDTO> listEquipmentLabelByEquipmentId(@PathVariable("equipmentId") Long equipmentId);

    /**
     * 查询分页设备参数信息
     *
     * @param equipmentId
     * @return
     * @throws ServiceException
     */
    @PostMapping("/queryParams/{equipmentId}")
    Map<String, String> queryParams(@PathVariable("equipmentId") Long equipmentId) throws ServiceException;

    /**
     * 通过设备code查询设备信息
     *
     * @param dockIdentifier
     * @return
     * @throws ServiceException
     */
    @ApiOperation("通过设备对接标识查询设备信息")
    @ApiImplicitParam(name = "dockIdentifier", value = "设备对接标识", required = true, paramType = "path")
    @ApiOperationSupport(order = 8)
    @GetMapping("/detailsEquDockIdentifier/{dockIdentifier}")
    EquipmentInfoDTO detailsEquDockIdentifier(@PathVariable("dockIdentifier") String dockIdentifier) throws ServiceException;

    @ApiOperation("获取所有设备关系")
    @ApiOperationSupport(order = 10)
    @GetMapping("/list-all-gateway-relation")
    List<EquipmentGatewayRelationDTO> listAllRelation() throws ServiceException;

}
